[SPARK-47723][CORE][TESTS] Introduce a tool that can sort alphabetically enumeration field in LogEntry automatically#45867
[SPARK-47723][CORE][TESTS] Introduce a tool that can sort alphabetically enumeration field in LogEntry automatically#45867panbingkun wants to merge 8 commits into
LogEntry automatically#45867Conversation
…lly enumeration field in `LogEntry` automatically
LogEntry automaticallyLogEntry automatically
LogEntry automaticallyLogEntry automatically
| test("LogKey enumeration fields are correctly sorted") { | ||
| val originalKeys = LogKey.values.toSeq | ||
| val sortedKeys = originalKeys.sortBy(_.toString) | ||
| if (regenerateGoldenFiles) { |
There was a problem hiding this comment.
Let's move the regeneration to a new method instead of keeping in the test case.
There was a problem hiding this comment.
Do you mean: extract the regenerated method into an independent method and call it in that place?
spark/core/src/test/scala/org/apache/spark/SparkThrowableSuite.scala
Lines 90 to 117 in 3f6ac60
The basic idea is that when without setting environment variables SPARK_GENERATE_GOLDEN_FILES (default is false), the UT will only check whether the enumeration fields in LogKey have been sorted alphabetically.
The steps used in my process of migrating error classes are roughly as follows:
- Before I submit the changes, if I
rememberthe formatting step, I will use the following command to regenerate the error classes fileerror-classes.jsonand submit them.
SPARK_GENERATE_GOLDEN_FILES=1 build/sbt "core/testOnly *SparkThrowableSuite -- -t \"Error classes are correctly formatted\""
- If I
forgetthis step, if there are incorrect item inerror-classes.jsonthat are not sorted alphabetically, GA will help me discover (UT failed), then I will execute above command on local and resubmit the changes.
I guess our scene is very similar to this.
There was a problem hiding this comment.
Yeah, create a new method in this file .
There was a problem hiding this comment.
Okay, let me do it right now.
| /* Used to regenerate the LogKey class file. Run: | ||
| {{{ | ||
| SPARK_GENERATE_GOLDEN_FILES=1 build/sbt \ | ||
| "common-utils/testOnly *LogKeySuite -- -t \"LogKey enumeration fields are correctly sorted\"" |
There was a problem hiding this comment.
Shall we remove the -t ... from the instruction to make it simpler?
|
@gengliangwang all done. |
Co-authored-by: Gengliang Wang <gengliang@apache.org>
| val keys = LogKey.values.toSeq | ||
| assert(keys === keys.sortBy(_.toString), | ||
| "LogKey enumeration fields must be sorted alphabetically") | ||
| // scalastyle:off line.size.limit |
| assert(keys === keys.sortBy(_.toString), | ||
| "LogKey enumeration fields must be sorted alphabetically") | ||
| // scalastyle:off line.size.limit | ||
| /* Used to regenerate the LogKey class file. Run: |
There was a problem hiding this comment.
Let's move this before line 32 class LogKeySuite
|
Thanks, merging to master |
What changes were proposed in this pull request?
The pr aims to
introduceatoolthat cansort alphabeticallyenumeration field inLogEntryautomatically.Why are the changes needed?
Enable developers to more conveniently write the enumeration values in
LogEntryin alphabetical order according to the requirements of structured log development documents.Does this PR introduce any user-facing change?
No.
How was this patch tested?
Was this patch authored or co-authored using generative AI tooling?
No.